// Copyright 2011 Jefferson Willian
// willmont7@gmail.com

#include <cstdio>
#include <algorithm>

using std::sort;

int main() {
  int n;
  int pont;
  int type;
  int higher;
  int cards[5];
  int allcards[14];
  int x;

  scanf("%d", &n);

  for (int i = 1;i <= n;i++) {
    scanf("%d%d%d%d%d", &cards[0], &cards[1], &cards[2], &cards[3], &cards[4]);

    sort(cards, cards+5);

    type = 0;

    /* Verifica se eh sequencia */
    if (cards[1] == cards[0]+1)
      if (cards[2] == cards[1]+1)
        if (cards[3] == cards[2]+1)
          if (cards[4] == cards[3]+1) {
            type = 1;
            x = cards[0];
            goto final;
          }

    for (int j = 1;j < 14;j++)
      allcards[j] = 0;
    for (int j = 0;j < 5;j++)
      allcards[cards[j]]++;

    higher = 1;
    for (int j = 1;j < 14;j++)
      if (allcards[j] > allcards[higher])
        higher = j;

    /* Verifica se tem 4 cartas iguas */
    if (allcards[higher] == 4) {
      type = 2;
      x = higher;
      goto final;
    }

    /* Verifica se tem 3 cartas iguais */
    if (allcards[higher] == 3) {
      /* Verifica se tem mais duas cartas iguais */
      for (int j = 1;j < 14;j++)
        if (allcards[j] == 2) {
          type = 3;
          x = higher;
          goto final;
        }
      type = 4;
      x = higher;
      goto final;
    }

    /* Verifica se tem duas cartas iguais */
    if (allcards[higher] == 2) {
      /* Verifica se tem mais duas cartas iguais */
      for (int j = 1;j < 14;j++)
        if (j != higher && allcards[j] == 2) {
          type = 5;
          if (higher > j)
            x = 3*higher+2*j;
          else
            x = 3*j+2*higher;
          goto final;
        }
      type = 6;
      x = higher;
      goto final;
    }

    final:

    if (type == 0)
      pont = 0;
    else if (type == 1)
      pont = x+200;
    else if (type == 2)
      pont = x+180;
    else if (type == 3)
      pont = x+160;
    else if (type == 4)
      pont = x+140;
    else if (type == 5)
      pont = x+20;
    else if (type == 6)
      pont = x;

    printf("Teste %d\n%d\n\n", i, pont);
  }

  return 0;
}
